/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-23
 * Time: 21:57
 */
//力扣1004  最大连续1的个数III
class Solution {
    public int longestOnes(int[] nums, int k) {
        //滑动窗口
        int n = nums.length;
        int countZero = 0;
        int left = 0;
        int maxLen = 0;
        for (int right = 0; right < n; right++) {//进窗口
            if (nums[right] == 0) {
                countZero++;
            }
            while (countZero > k) {//判断s
                if (nums[left] == 0) {
                    countZero--;
                }
                left++;//出窗口
            }
            maxLen = Math.max(maxLen, right - left + 1);//更新结果
        }
        return maxLen;
    }
}